<template>
	<a-card>
	<a-row style="margin-bottom: 1rem">
		<!--放置搜索条件-->
		<a-col :span="2">
			<a-select
				ref="select"
				v-model:value=this.synSeachBo.status
				style="width: 80px;margin-top: 5px;"
				@focus="focus"
				@change="onSearch"
				placeholder="状态"
			>
				<a-select-option value="0">禁用</a-select-option>
				<a-select-option value="1">启用</a-select-option>
				<a-select-option value="">全部</a-select-option>
			</a-select>
		</a-col>
		<a-col :span="7">
			<a-input-search
				v-model:value=this.synSeachBo.keyword
				placeholder="搜索关键字"
				enter-button="搜索"
				size="large"
				@search="onSearch"
			/>
		</a-col>
		<a-col :push=this.number :span="2">
			<a-button type="primary" style="width: 90px;height: 40px" @click="showDrawer">
				<PlusOutlined/>
				添加
			</a-button>
		</a-col>
	</a-row>
	<!--添加抽屉-->
	<a-drawer :width="750" :title="opSynActInfoBo.id==null||opSynActInfoBo.id==''?'添加合成活动':'编辑合成活动'"
			  placement="right" v-model:open="this.open" @close="onClose">
		<template #extra>
			<a-button style="margin-right: 8px" @click="onClose">重置</a-button>
			<a-button type="primary" @click="addSynInfo" html-type="submit">保存</a-button>
		</template>
		<a-form layout="vertical" :model="opSynActInfoBo" ref="formRef">
			<a-card title="基本信息" style="margin-top: 1rem">
				<a-form-item name="name" label="活动名称" :rules="{required: true,message:'请填写活动名称',trigger:'blur'}">
					<a-input v-model:value="opSynActInfoBo.name" placeholder="请填写活动名称"/>
				</a-form-item>
				<a-row :gutter="24">
					<a-col :span="12">
						<a-form-item name="startTime" label="开始时间"
									 :rules="{required: true,message:'请选择开始时间',trigger:'blur'}">
							<a-date-picker v-model:value="this.opSynActInfoBo.startTime" show-time type="date"
										   value-format="YYYY-MM-DD HH:mm:ss"
										   placeholder="选择开始时间"/>
						</a-form-item>
					</a-col>
					<a-col :span="12">
						<a-form-item name="endTime" label="结束时间"
									 :rules="{required: true, message: '请选择结束时间', trigger: ['change', 'blur']}">
							<a-date-picker v-model:value="this.opSynActInfoBo.endTime" show-time type="date"
										   value-format="YYYY-MM-DD HH:mm:ss"
										   placeholder="选择结束时间"/>
						</a-form-item>
					</a-col>
				</a-row>
				<a-form-item name="remark" label="活动介绍" style="margin-left: 0.2rem">
					<a-textarea v-model:value="this.opSynActInfoBo.remark" placeholder="请填写活动名称"/>
				</a-form-item>
			</a-card>
			<!--      新增合成后艺术品  -->
			<a-card title="合成后藏品信息" style="margin-top: 1rem">
				<a-row :gutter="24">
					<template v-for="(collecrules,index) in this.opSynActInfoBo.opSynActRulesBos">
						<a-col :span="7">
							<a-form-item label="合成后藏品" :name="['opSynActRulesBos', index, 'nftId']"
										 :rules="{ required: true,message:'请选择合成后藏品',trigger:'blur'}">
								<a-select
									v-model:value="collecrules.nftId" show-search :options="filterInfo.options"
									:field-names="filterInfo.fieldNames"
									option-filter-prop="name" placeholder="请选择合成后藏品" style="width:100%"
									@change="changeInventory(collecrules.nftId,index)">
								</a-select>
							</a-form-item>
						</a-col>
						<a-col :span="5">
							<a-form-item label="数量" :name="['opSynActRulesBos', index, 'quantity']"
										 :rules="[{ required: true,message:'请填写数量',trigger:'blur'}]">
								<a-input-number id="inputNumber" v-model:value="collecrules.quantity" :min="1" :max="1"
												placeholder="数量"/>
							</a-form-item>
						</a-col>
						<a-col :span="5">
							<a-form-item label="库存" :name="['opSynActRulesBos', index, 'inventory']"
										 :rules="[{ required: true,message:'请填写库存',trigger:'blur'}]">
								<!--,{required:/^[A-Za-z0-9]{4,40}$/ === this.invent,message:'超过库存数量'}-->
								<a-input-number id="inputNumber" v-model:value="collecrules.inventory" :min="1" :max="collecrules.invent"
												:placeholder="collecrules.invent"/>
							</a-form-item>
						</a-col>
						<a-col :span="5">
							<a-form-item label="概率" :name="['opSynActRulesBos', index, 'probability']"
										 :rules="{ required: true,message:'请填写概率',trigger:'blur'}">
								<a-input-number id="inputNumber" v-model:value="collecrules.probability" :min="1" :max="100"
												placeholder="百分比"/>
							</a-form-item>
						</a-col>
						<a-col :span="2" style="margin-top: 2.2rem">
							<MinusCircleOutlined @click="delColl(index,collecrules.nftId)"/>
						</a-col>
					</template>
					<a-button type="dashed" style="width: 100%" @click="addCollecRules">
						新增合成后藏品
					</a-button>
				</a-row>
			</a-card>
			<!--原材料信息  -->
			<a-card title="原材料信息" style="margin-top: 1rem">
				<a-form-item>
					<a-row :gutter="24">
						<template v-for="(rawMat,index) in this.opSynActInfoBo.opSynMaterBos">
							<a-col :span="17">
								<a-form-item label="原材料藏品" :name="['opSynMaterBos', index, 'nftId']"
											 :rules="{ required: true ,message:'请选择原材料',trigger:'blur'}">
									<a-select
										v-model:value="rawMat.nftId" show-search :options="filterInfoList.options"
										:field-names="filterInfoList.fieldNames"
										option-filter-prop="name" placeholder="请选择原材料" style="width:100%">
									</a-select>
								</a-form-item>
							</a-col>
							<a-col :span="5">
								<a-form-item label="数量" :name="['opSynMaterBos', index, 'quantity']"
											 :rules="{ required: true,message:'请填写数量',trigger:'blur'}">
									<a-input-number id="inputNumber" v-model:value="rawMat.quantity" :min="1" :max="9999"
													placeholder="数量"/>
								</a-form-item>
							</a-col>
							<a-col :span="2" style="margin-top: 2.2rem">
								<MinusCircleOutlined @click="delRawMat(index)"/>
							</a-col>
						</template>
					</a-row>
					<a-button type="dashed" style="width: 100%" @click="addRawMat">
						新增原材料信息
					</a-button>
				</a-form-item>
			</a-card>
			<!-- 门槛信息-->
			<a-card title="门槛信息" style="margin-top: 1rem">
				<table v-for="(door,inde) in opSynActInfoBo.opSynDoorsRelBos" style="width: 750px;margin-bottom: 1rem">
					<tr>
						<td style="width: 30px;font-size: 1.5rem">
							<PlusOutlined @click="addDoors(door.opSynDoorsRulesBos)"/>
						</td>
						<td style="width: 20px">
							<a-form-item label="序号">
								<a-input-number id="inputNumber" v-model:value="door.doorRulesNum" :min="1" :max="60"
												placeholder="请填写序号"/>
							</a-form-item>
						</td>
						<a-card style="width: 530px;margin-left: 10px">
							<table v-for="(doors,index) in door.opSynDoorsRulesBos">
								<tr>
									<td style="width: 200px;">
										<a-form-item label="门槛藏品">
											<a-select
												v-model:value="doors.nftId" show-search :options="filterInfoList.options"
												:field-names="filterInfoList.fieldNames"
												option-filter-prop="name" placeholder="门槛藏品">
											</a-select>
										</a-form-item>
									</td>
									<td style="width: 200px;">
										<a-form-item label="数量" style="margin-left: 80px">
											<a-input-number id="inputNumber" v-model:value="doors.quantity" :min="1" :max="9999"
															placeholder="数量"/>
										</a-form-item>
									</td>
									<td style="vertical-align: middle;">
										<MinusCircleOutlined @click="delDoors(door.opSynDoorsRulesBos,index,inde)"
															 style="margin-left: 50px"/>
									</td>
								</tr>
							</table>
						</a-card>
					</tr>
				</table>
				<a-button type="dashed" style="width: 100%" @click="addDoor">
					新增门槛信息
				</a-button>
			</a-card>
		</a-form>
	</a-drawer>
	<!-- 列表-->
	<a-row style="margin-bottom: 1rem">
		<a-col :span="24">
			<a-table :columns="columns" :data-source="dataSource" :pagination="false">
				<template #bodyCell="{ column, record }">
					<!--合成藏品-->
					<template v-if="column.key === 'synRulesName'">
						<a-row style="margin-top: 0.5rem" v-for="synRules in record.opSynActRulesVos">
							<a-col>
								<img :src="synRules.cover" width="50" height="50"/>
							</a-col>
							<a-col style="margin: auto">
								<a @click="getNft(synRules.nftId)">{{ synRules.name }}</a>
								<br/>
								<span>X1</span>
							</a-col>
						</a-row>
					</template>
					<!--库存-->
					<template v-if="column.key === 'inventory'">
						<table>
							<tr v-for="synRules in record.opSynActRulesVos">
								<td style="height: 3.5rem">{{ synRules.inventory }}</td>
							</tr>
						</table>
					</template>
					<!--状态-->
					<template v-if="column.key === 'status'">
						<a-tag v-if="record.status==0" :bordered="false" color="default">未启用</a-tag>
						<a-tag v-if="record.status==1" :bordered="false" color="orange">已开始</a-tag>
						<a-tag v-if="record.status==2" :bordered="false" color="success">进行中</a-tag>
						<a-tag v-if="record.status==3" :bordered="false" color="error">已结束</a-tag>
					</template>
					<!--所需原料-->
					<template v-if="column.key === 'synMatName'">
						<a-row style="margin-top: 0.5rem" v-for="synMat in record.opSynMaterVos">
							<a-col>
								<img :src="synMat.cover" width="50" height="50">
							</a-col>
							<a-col style="margin: auto">
								<a @click="getNft(synMat.nftId)">{{ synMat.name }}</a>
								<br/>
								<span>X{{ synMat.quantity }}</span>
							</a-col>
						</a-row>
					</template>
					<!--门槛信息-->
					<template v-if="column.key === 'doors'">
						<a-tag :bordered="false" color="success" style="cursor: pointer"
							   @click="getDoors(record.opSynDoorsRelVos)">
							查看门槛信息
						</a-tag>



<!--						<a-row style="margin-top: 0.5rem" v-for="door in record.opSynDoorsRelVos">-->
<!--							<a-col style="font-size: 1.5rem;">-->
<!--								{{ door.doorRulesNum }}:-->
<!--							</a-col>-->
<!--							<a-row v-for="doors in door.opSynDoorsRulesVos">-->
<!--								<a-col>-->
<!--									<img :src="doors.cover" width="50" height="50">-->
<!--								</a-col>-->
<!--								<a-col style="margin: auto">-->
<!--									<a @click="getNft(doors.nftId)">{{ doors.name }}</a>-->
<!--									<br/>-->
<!--									<span>X{{ doors.quantity }}</span>-->
<!--								</a-col>-->
<!--							</a-row>-->
<!--						</a-row>-->
					</template>
					<!--活动时间范围-->
					<template v-if="column.key === 'startAndEndTime'">
						<div>
							<span>{{ record.startTime }}<br/>{{ record.endTime }}</span>
						</div>
					</template>
					<!--操作-->
					<template v-if="column.key === 'action'">
						<a-dropdown>
							<template #overlay>
								<a-menu>
									<a-menu-item key="1" v-if="record.status==0" @click="enableSyn(record.id)">
										启用
									</a-menu-item>
									<a-menu-item key="2" v-if="record.status==0" @click="updateSyn(record.id)">
										编辑
									</a-menu-item>
									<a-menu-item key="3" v-if="record.status==0" @click="delSyn(record.id)">
										删除
									</a-menu-item>
									<a-menu-item key="4" v-if="record.status==0" @click="updateInven(record.id)">
										修改库存
									</a-menu-item>
									<a-menu-item key="5" v-if="record.status==1" @click="disableSyn(record.id)">
										禁用
									</a-menu-item>
									<a-menu-item key="6" @click="getSyn(record.id)">
										查看
									</a-menu-item>
									<a-menu-item key="7" @click="getSynInfo(record.id)">
										查看合成记录
									</a-menu-item>
								</a-menu>
							</template>
							<a-button>
								操作<DownOutlined/>
							</a-button>
						</a-dropdown>
					</template>
				</template>
			</a-table>
		</a-col>
	</a-row>
	<a-flex justify="flex-end">
		<a-pagination
			size="small"
			@change="onChange"
			show-size-changer
			:pageSizeOptions="['5','10','20','50','100']"
			v-model:current="this.page.pageNo"
			v-model:page-size="this.page.pageSize"
			:total="this.page.total"
			:show-total="(total, range) => `${range[0]}-${range[1]} 共 ${total} 条`"/>
	</a-flex>
	<!--  查看详情-->
	<template>
		<a-modal v-model:open="this.openn" width="1000px" title="查看合成活动" :model="opSynActInfoVo">
			<a-card title="基本信息" style="width: 950px;margin-bottom: 20px">
				<!--基本信息-->
				<a-descriptions :column="1">
					<a-descriptions-item label="活动名称">{{ opSynActInfoVo.name }}</a-descriptions-item>
					<a-descriptions-item label="时间范围">{{ opSynActInfoVo.startTime }} 到 {{ opSynActInfoVo.endTime }}
					</a-descriptions-item>
					<a-descriptions-item label="创建时间">{{ opSynActInfoVo.createTime }}</a-descriptions-item>
					<a-descriptions-item label="活动介绍">{{ opSynActInfoVo.remark }}</a-descriptions-item>
				</a-descriptions>
			</a-card>
			<!--合成藏品信息-->
			<a-row style="margin-bottom: 1rem">
				<a-col :span="24">
					<a-card title="合成后藏品信息">
						<a-table :columns="collecolumns" :data-source="dataColl" :pagination="false">
							<template #bodyCell="{ column, record }">
								<template v-if="column.key === 'cover'">
									<a-image :width="50" :height="50" :src="record.cover"/>
								</template>
							</template>
						</a-table>
					</a-card>
				</a-col>
			</a-row>
			<!--合成原材料信息-->
			<a-row style="margin-bottom: 1rem">
				<a-col :span="24">
					<a-card title="合成原材料信息">
						<a-table :columns="rawMatcolumns" :data-source="dataRaw" :pagination="false">
							<template #bodyCell="{ column, record }">
								<template v-if="column.key === 'cover'">
									<a-image :width="50" :height="50" :src="record.cover"/>
								</template>
							</template>
						</a-table>
					</a-card>
				</a-col>
			</a-row>
			<!--门槛信息-->
			<a-row style="margin-bottom: 1rem">
				<a-col :span="24">
					<a-card title="门槛信息">
						<a-table :columns="doorscolumns" :data-source="dataDoor" :pagination="false">
							<template #bodyCell="{ column, record }">
								<template v-if="column.key === 'nftInfo'">
									<a-row v-for="doors in record.opSynDoorsRulesVos">
										<a-col>
											<img :src="doors.cover" width="50" height="50">
										</a-col>
										<a-col style="margin-bottom: 20px">
											<a href="{{doors.cover}}">{{ doors.name }}</a>
											<br/>
											<span>X{{ doors.quantity }}</span>
										</a-col>
									</a-row>
								</template>
							</template>
						</a-table>
					</a-card>
				</a-col>
			</a-row>
		</a-modal>
	</template>
	<!--  查看合成记录-->
	<template>
		<a-modal v-model:open="this.ope" width="1000px" title="查看合成记录" :model="opSynRecordLog">
			<a-card title="合成记录信息">
				<a-table :columns="synRecLogCoumls" :data-source="opSynRecordLog" :pagination="false">
					<template #bodyCell="{ column, record }">

					</template>
				</a-table>
			</a-card>
		</a-modal>
	</template>
	<!--修改库存-->
	<template>
		<a-modal v-model:open="this.opennn" width="1000px" :model="synActRulesBo" @ok="handleOk(synActRulesBo)">
			<a-card title="修改合成藏品库存">
				<a-table :columns="synActRulCoumls" :data-source="synActRulesBo" :pagination="false">
					<template #bodyCell="{ column, record }">
						<template v-if="column.key === 'inventory'">
							<a-input-number v-model:value="record.inventory" :min="1" :max="100000"/>
						</template>
					</template>
				</a-table>
			</a-card>
		</a-modal>
	</template>
	<!--门槛信息-->
	<template>
		<a-modal v-model:open="this.dooors" width="1000px">
			<a-card title="门槛信息">
				<a-table :columns="doorscolumns" :data-source="doores" :pagination="false">
					<template #bodyCell="{ column, record }">
						<template v-if="column.key === 'nftInfo'">
							<a-row v-for="doors in record.opSynDoorsRulesVos">
								<a-col>
									<img :src="doors.cover" width="50" height="50">
								</a-col>
								<a-col style="margin-bottom: 20px">
									<a href="{{doors.cover}}">{{ doors.name }}</a>
									<br/>
									<span>X{{ doors.quantity }}</span>
								</a-col>
							</a-row>
						</template>
					</template>
				</a-table>
			</a-card>
		</a-modal>
	</template>
	<GatNftInfo ref="getNftInfo"></GatNftInfo>
	</a-card>
</template>

<script>
import {MinusCircleOutlined, PlusOutlined} from '@ant-design/icons-vue';
import Optlog from "../sysLog/Optlog.vue";
import {message} from "ant-design-vue";
import dayjs from "dayjs";
import Synthesis from "@/api/nft/activity/Synthesis";
import SynLog from "@/api/nft/activity/SynLog";
export default {
	name: "Synthesis",
	components: {
		Optlog,
		MinusCircleOutlined,
		PlusOutlined,
	},
	data() {
		return {
			dooors:false,
			id: null,
			key: 'updatable',
			filterInfo: {
				fieldNames: {label: 'name', value: 'id'},
				options: [],
			},
			filterInfoList: {
				fieldNames: {label: 'name', value: 'id'},
				options: [],
			},
			Inventory: null,
			SumInventory: null,
			dataSource: [],
			dataColl: [],
			dataRaw: [],
			dataDoor: [],
			pagination: 9,
			number: 13,
			open: false,
			openn: false,
			opennn: false,
			ope: false,
			// nftList: [],
			dcNftQueryBo: {
				type: 3
			},
			page: {
				pageNo: 1,
				pageSize: 5,
				total: 0
			},
			synSeachBo: {
				keyword: '',
				status: ''
			},
			synActRulCoumls: [
				{
					title: '藏品名称',
					dataIndex: 'name',
					key: 'name',
				},
				{
					title: '藏品库存',
					dataIndex: 'inventory',
					key: 'inventory',
				}],
			columns: [
				{
					title: '活动标题',
					dataIndex: 'name',
					key: 'name',
				},
				{
					title: '合成后的艺术品',
					key: 'synRulesName',
				},
				{
					title: '库存',
					key: 'inventory',
				},
				{
					title: '状态',
					dataIndex: 'status',
					key: 'status',
				},
				{
					title: '所需原料',
					key: 'synMatName',
				},
				{
					title: '门槛信息',
					key: 'doors',
				},
				{
					title: '活动时间范围',
					key: 'startAndEndTime',
				},
				{
					title: '创建时间',
					dataIndex: 'createTime',
					key: 'createTime',
				},
				{
					title: '操作',
					key: 'action',
				},
			],
			//查看列表
			rawMatcolumns: [{
				title: '藏品名称',
				dataIndex: 'name',
				key: 'name',
			}, {
				title: '藏品图片',
				dataIndex: 'cover',
				key: 'cover',
			}, {
				title: '藏品数量',
				dataIndex: 'quantity',
				key: 'quantity',
			}],
			collecolumns: [{
				title: '藏品名称',
				dataIndex: 'name',
				key: 'name',
			}, {
				title: '藏品图片',
				key: 'cover',
			}, {
				title: '藏品数量',
				dataIndex: 'quantity',
				key: 'quantity',
			}, {
				title: '藏品库存',
				dataIndex: 'inventory',
				key: 'inventory',
			}, {
				title: '藏品概率',
				dataIndex: 'probability',
				key: 'probability',
			}],
			doorscolumns: [{
				title: '序号',
				dataIndex: 'doorRulesNum',
				key: 'doorRulesNum',
			}, {
				title: '藏品信息',
				dataIndex: 'nftInfo',
				key: 'nftInfo',
			}],
			//合成记录信息列表
			synRecLogCoumls: [{
				title: '会员手机号',
				dataIndex: 'phone',
				key: 'phone',
			}, {
				title: '会员名称',
				dataIndex: 'userName',
				key: 'userName',
			}, {
				title: '藏品链上标识',
				dataIndex: 'chainAddr',
				key: 'chainAddr',
			}, {
				title: '合成状态',
				dataIndex: 'status',
				key: 'status',
			}, {
				title: '合成时间',
				dataIndex: 'synTime',
				key: 'synTime',
			}],
			opSynRecordLog: {
				id: null,
				phone: null,
				userName: null,
				chainAddr: null,
				status: null,
				synTime: null
			},
			opSynActInfoBo: {
				id: '',
				name: '',
				startTime: '',
				endTime: '',
				remark: '',
				opSynMaterBos: [{
					nftId: '',
					quantity: ''
				}],
				opSynActRulesBos: [{
					nftId: '',
					quantity: '',
					inventory: '',
					probability: '',
					invent: null,
				}],
				opSynDoorsRelBos: [{
					doorRulesNum: '',
					opSynDoorsRulesBos: [{
						nftId: '',
						quantity: ''
					}]
				}]
			},
			synActRulesBo: [{
				id: null,
				nftId: null,
				name: null,
				inventory: null,
				probability: null,
				invent: null
			}],
			opSynActInfoVo: {
				id: null,
				name: null,
				startTime: null,
				endTime: null,
				remark: null,
				createTime: null,
				opSynMaterVos: [{
					id: null,
					nftId: null,
					name: null,
					cover: null,
					quantity: null
				}
				],
				opSynActRulesVos: [{
					id: null,
					nftId: null,
					name: null,
					cover: null,
					quantity: null,
					inventory: null,
					probability: null,
				}],
				opSynDoorsRelVos: [{
					id: null,
					doorRulesNum: null,
					opSynDoorsRulesVos: [{
						id: null,
						nftId: null,
						name: null,
						cover: null,
						quantity: null
					}]
				}]
			},
			doores:[]
		};
	},
	methods: {
		getDoors(data){
			this.doores = data;
			this.dooors = true;
		},
		//添加抽屉
		showDrawer() {
			this.open = true;
			this.respForm()
		},
		onClose() {
			this.$refs['formRef'].resetFields();
			this.open = false;
		},
		//追加合成后藏品
		addCollecRules() {
			this.opSynActInfoBo.opSynActRulesBos.push({nftId: '', quantity: '', inventory: '', probability: ''})
		},
		//追加原材料信息
		addRawMat() {
			this.opSynActInfoBo.opSynMaterBos.push({nftId: '', quantity: ''})
		},
		//追加门槛信息
		addDoor() {
			this.opSynActInfoBo.opSynDoorsRelBos.push({doorRulesNum: '', opSynDoorsRulesBos: [{nftId: '', quantity: ''}]})
		},
		//追加具体门槛信息
		addDoors(opSynDoorsRulesBos) {
			opSynDoorsRulesBos.push({nftId: '', quantity: ''})
		},
		//删除门槛信息
		delDoors(list, index, inde) {
			list.splice(index, 1);
			if (list.length == 0) {
				this.opSynActInfoBo.opSynDoorsRelBos.splice(inde, 1);
			}
		},
		//删除原材料信息
		delRawMat(index) {
			if (index !== 0) {
				this.opSynActInfoBo.opSynMaterBos.splice(index, 1);
			}
		},
		//删除合成后藏品
		delColl(index,nftId) {
			if (index !== 0) {
				this.opSynActInfoBo.opSynActRulesBos.splice(index, 1);
			}
		},
		//添加
		addSynInfo() {
			debugger
			let probabil;
			let key = this.key;
			let formRef = this.$refs.formRef;
			formRef.validate().then(() => {
				debugger
				if (this.opSynActInfoBo.id == null || this.opSynActInfoBo.id == '') {
					if (this.opSynActInfoBo.startTime < this.opSynActInfoBo.endTime){
						for (let i = 0; i < this.opSynActInfoBo.opSynActRulesBos.length; i++) {
							let synCollecRulesInfoBo = this.opSynActInfoBo.opSynActRulesBos[i];
							let inventory = synCollecRulesInfoBo.inventory;
							if (inventory > synCollecRulesInfoBo.invent) {
								message.error('输入合成后藏品信息库存值不能大于' + synCollecRulesInfoBo.invent);
							}
							let probability = synCollecRulesInfoBo.probability;
							probabil = probabil + probability;
							if (probabil>100){
								message.error('概率总数不能大于100');
							}
						}
						Synthesis.addSynInfo(this.opSynActInfoBo).then((resp) => {
								this.query();
								this.open = false;
						})
					}else {
						message.error('开始时间不能大于结束时间');
					}
				} else {
					debugger
					if (this.opSynActInfoBo.startTime < this.opSynActInfoBo.endTime){
						for (let j = 0; j < this.opSynActInfoBo.opSynActRulesBos.length; j++) {
							let synCollecRulesInfoBo = this.opSynActInfoBo.opSynActRulesBos[j];
							let inventory = synCollecRulesInfoBo.inventory;
							if (inventory > synCollecRulesInfoBo.invent) {
								message.error('输入合成后藏品信息库存值不能大于' + synCollecRulesInfoBo.invent);
							}
							let probability1 = synCollecRulesInfoBo.probability;
							probabil = probabil + probability1;
							if (probabil>100){
								message.error('概率总数不能大于100');
							}
						}
						debugger
						Synthesis.updateSynInfo(this.opSynActInfoBo).then((resp) => {
							debugger
								this.query();
								this.open = false;
						})
					}else {
						message.error('开始时间不能大于结束时间');
					}
				}
			})
		},
		//启用
		enableSyn(id) {
			let key = this.key;
			Synthesis.enableSyn(id).then((resp) => {
					this.query();
			}).catch((error) => {
				message.error(error);
			})
		},
		//禁用
		disableSyn(id) {
			let key = this.key;
			Synthesis.disableSyn(id)
				.then((resp) => {
						this.query();
				}).catch((error) => {
				message.error(error);
			})
		},
		//删除
		delSyn(id) {
			let key = this.key;
			Synthesis.delSyn(id).then((resp) => {
					this.query();
			}).catch((error) => {
				message.error(error);
			})
		},
		//查看合成活动
		getSyn(id) {
			Synthesis.getSyn(id).then((resp) => {
				this.openn = true;
				this.opSynActInfoVo = resp;
				debugger
				this.dataColl = this.opSynActInfoVo.opSynActRulesVos;
				this.dataRaw = this.opSynActInfoVo.opSynMaterVos;
				this.dataDoor = this.opSynActInfoVo.opSynDoorsRelVos;
			})
		},
		//查看合成记录
		getSynInfo(nftId) {
			debugger
			SynLog.getSynInfo(nftId).then((resp) => {
				this.ope = true
				debugger
				this.opSynRecordLog = resp
			})
		},
		//编辑合成活动信息
		updateSyn(id) {
			debugger
			Synthesis.getSyn(id).then((resp) => {
				this.open = true;
				this.opSynActInfoBo.id = resp.id;
				this.opSynActInfoBo.name = resp.name;
				this.opSynActInfoBo.startTime = resp.startTime;
				this.opSynActInfoBo.endTime = resp.endTime;
				this.opSynActInfoBo.remark = resp.remark;
				this.opSynActInfoBo.opSynActRulesBos = resp.opSynActRulesVos;
				this.opSynActInfoBo.opSynMaterBos = resp.opSynMaterVos;
				this.opSynActInfoBo.opSynDoorsRelBos = resp.opSynDoorsRelVos;
				for (let i = 0; i < this.opSynActInfoBo.opSynDoorsRelBos.length; i++) {
					this.opSynActInfoBo.opSynDoorsRelBos[i].opSynDoorsRulesBos = resp.opSynDoorsRelVos[i].opSynDoorsRulesVos
				}
				for (let i = 0; i < this.opSynActInfoBo.opSynActRulesBos.length; i++) {
					debugger
					let synCollecRulesInfoBo = this.opSynActInfoBo.opSynActRulesBos[i];
					this.changeInventory(synCollecRulesInfoBo.nftId);
				}
			})
		},
		//修改合成藏品
		updateInven(id) {
			Synthesis.getSyn(id).then((resp) => {
				debugger
				this.opennn = true;
				this.id = resp.id;
				this.synActRulesBo = resp.opSynActRulesVos;
				for (let i = 0; i < this.synActRulesBo.length; i++) {
					let synActRules = this.synActRulesBo[i];
					this.changeInventory(synActRules.nftId)
				}
			})
		},
		//保存修改后的藏品库存数量
		handleOk(synActRulesBo) {
			debugger
			for (let i = 0; i < synActRulesBo.length; i++) {
				let synActRules = synActRulesBo[i];
				let inventory = synActRules.inventory;
				if (inventory > synActRules.invent) {
					message.error('输入库存值不能大于' + synActRules.invent);
				}else {
					Synthesis.handleOk(this.id,synActRulesBo).then((resp) => {
							this.opennn = false;
							this.query();
					}).catch((error) => {
						message.error(error);
					})
				}
			}
		},
		//初始化对象
		respForm() {
			this.opSynActInfoBo = {
				id: '',
				name: '',
				startTime: '',
				endTime: '',
				remark: '',
				opSynMaterBos: [{
					nftId: '',
					quantity: ''
				}],
				opSynActRulesBos: [{
					nftId: '',
					quantity: '',
					inventory: '',
					probability: '',
					invent:null
				}],
				opSynDoorsRelBos: [{
					doorRulesNum: '',
					opSynDoorsRulesBos: [{
						nftId: '',
						quantity: ''
					}]
				}]
			}
		},
		//查看藏品信息
		getNft(nftId) {
			this.$refs.getNftInfo.getNft(nftId)
		},
		//查看库存数量
		changeInventory(nfiId,index) {
			debugger
			SynLog.changeInventory(nfiId).then((resp) => {
				debugger
				this.Inventory = resp.inventory
				Synthesis.getInven(nfiId).then((resp) => {
					debugger
					this.opSynActInfoBo.opSynActRulesBos[index].invent =  this.Inventory - resp;
					this.synActRulesBo[index].invent = this.Inventory - resp;
				});
			});

		},
		//获取藏品信息
		nftListQuer() {
			SynLog.nftListQuer(this.dcNftQueryBo).then((resp) => {
				this.filterInfo.options = resp.records;
			})
		},
		//获取原材料和藏品信息
		nftListQuery() {
			SynLog.nftListQuery().then((resp) => {
				this.filterInfoList.options = resp.records;
			})
		},
		//搜索
		query() {
			Synthesis.query(this.page.pageNo,this.page.pageSize,this.synSeachBo).then((resp) => {
				debugger
				this.page.total = resp.total;
				this.page.pageSize = resp.size;
				this.dataSource = resp.records;
			})
		},
		//关键字搜索
		onSearch() {
			debugger
			this.page.pageNO = 1
			this.query();
		},
		//点击分页
		onChange(pageNo) {
			this.query();
			this.page.pageNO = pageNo
		}
	},//加载完成
	mounted() {
		this.query();
		this.nftListQuer();
		this.nftListQuery();
	}

};
</script>
<style scoped>

</style>
<script setup>
</script>
